package com.aliyun.oss.userController;

import com.aliyun.oss.UserService.WxUserService;
import com.aliyun.oss.pojo.Vo.ResultVO;
import com.aliyun.oss.pojo.Vo.WxUserVO;
import com.aliyun.oss.utils.JwtUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RequestMapping("/user/user")
@RestController
public class WxLoginController {
    @Autowired
    WxUserService wxUserService;
    @PostMapping("/login")
    public ResultVO login(@RequestBody Map<String,Object> map) throws JsonProcessingException {
        String code = (String) map.get("code");
        WxUserVO wxUserVO=wxUserService.wxLogin(code);
        if(wxUserVO!=null){
            HashMap<String,Object> Wxmap=new HashMap<>();
            Wxmap.put("id",wxUserVO.getId());
            String token = JwtUtils.createToken(Wxmap);
            wxUserVO.setToken(token);
        }
        return ResultVO.success(wxUserVO);
    }
}
